#include "SampleChatClient.h"
TCPConnection *ChatClientFabric(TCPMan *pManager, TCPServer *pServer, 
								const char *szAddress, WORD wPort)
{
	return (TCPConnection*) new ChatClient(szAddress, wPort, pManager);
}

void ChatClient::OnPack(const char *pPacket, unsigned short int wSize)
{
	std::cout.write(pPacket, wSize);
	std::cout<<std::endl;
};

void ChatClient::OnConnect()
{
	std::cout<<"You in chat!"<<std::endl;
};
void ChatClient::OnDisconnect()
{
	std::cout<<"You has quit a chat!"<<std::endl;
};
void ChatClient::OnError(long lError, const char *szErrorDesc)
{
	TCPConnection::OnError(lError, szErrorDesc);
};

void ChatClient::SendMsg(std::string sMsg)
{
	char cMsgHeader = '\002';
	string sMessage = cMsgHeader+sMsg+'\0';
	SendPack(sMessage.c_str(), sMessage.size());
}

void ChatClient::ChangeNick(string sNick)
{
	char cNickHeader = '\001';
	string sMessage = cNickHeader+sNick+'\0';
	SendPack(sMessage.c_str(), sMessage.size());
}